<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
        <html><head>
        <link rel="stylesheet" type="text/css" href="apidocs.css"/>
        <title>API docs for &ldquo;sympy.simplify.rewrite&rdquo;</title>
        </head>
        <body><h1 class="module">Module s.s.rewrite</h1><span id="part">Part of <a href="sympy.simplify.html">sympy.simplify</a></span><div class="toplevel"><div><p>Module 'rewrite.py' contains advanced term rewriting methods concerning 
partial fraction decomposition, combinig together and collecting terms.</p>
</div></div><table class="children"><tr class="function"><td>Function</td><td><a href="#sympy.simplify.rewrite.cancel">cancel</a></td><td><div><p>Cancel common factors in a given rational function.</p>
</div></td></tr><tr class="function"><td>Function</td><td><a href="#sympy.simplify.rewrite.trim">trim</a></td><td><div><p>Cancel common factors in a given formal rational expression.</p>
</div></td></tr><tr class="function"><td>Function</td><td><a href="#sympy.simplify.rewrite.apart">apart</a></td><td><div><p>Compute partial fraction decomposition of a rational function.</p>
</div></td></tr></table>
            <div class="function">
            <div class="functionHeader">def <a name="sympy.simplify.rewrite.cancel">cancel(f, *syms, **flags):</a></div>
            <div class="functionBody"><div><p>Cancel common factors in a given rational function.</p>
<p>Given a quotient of polynomials, performing only gcd and quo operations 
in polynomial algebra,  return rational function with numerator and 
denominator of minimal total degree in an expanded form.</p>
<p>For all other kinds of expressions the input is returned in an unchanged
form. Note however, that 'cancel' function can thread over sums and 
relational operators.</p>
<p>Additionally you can specify a list of variables to perform cancelation 
more efficiently using only those symbols.</p>
<pre class="py-doctest">
<span class="py-prompt">&gt;&gt;&gt; </span><span class="py-keyword">from</span> sympy <span class="py-keyword">import</span> *
<span class="py-prompt">&gt;&gt;&gt; </span>x,y = symbols(<span class="py-string">'xy'</span>)</pre>
<pre class="py-doctest">
<span class="py-prompt">&gt;&gt;&gt; </span>cancel((x**2-1)/(x-1))
<span class="py-output">1 + x</span></pre>
<pre class="py-doctest">
<span class="py-prompt">&gt;&gt;&gt; </span>cancel((x**2-y**2)/(x-y), x)
<span class="py-output">x + y</span></pre>
<pre class="py-doctest">
<span class="py-prompt">&gt;&gt;&gt; </span>cancel((x**2-2)/(x+sqrt(2)))
<span class="py-output">x - 2**(1/2)</span></pre>
</div></div>
            </div>
            <div class="function">
            <div class="functionHeader">def <a name="sympy.simplify.rewrite.trim">trim(f, *syms, **flags):</a></div>
            <div class="functionBody"><div><p>Cancel common factors in a given formal rational expression.</p>
<p>Given an arbitrary expression, map all functional components to 
temporary symbols, rewriting this expression to rational function form and 
perform cancelation of common factors.</p>
<p>When given a rational function or a list of symbols discards all 
functional components, then this procedure is equivalent to cancel().</p>
<p>Note that this procedure can thread over composite objects like big 
operators, matrices, relational operators etc. It can be also called 
recursively (to change this behaviour unset 'recursive' flag).</p>
<pre class="py-doctest">
<span class="py-prompt">&gt;&gt;&gt; </span><span class="py-keyword">from</span> sympy <span class="py-keyword">import</span> *</pre>
<pre class="py-doctest">
<span class="py-prompt">&gt;&gt;&gt; </span>x,y = symbols(<span class="py-string">'xy'</span>)
<span class="py-prompt">&gt;&gt;&gt; </span>f = Function(<span class="py-string">'f'</span>)</pre>
<pre class="py-doctest">
<span class="py-prompt">&gt;&gt;&gt; </span>trim((f(x)**2+f(x))/f(x))
<span class="py-output">1 + f(x)</span></pre>
<pre class="py-doctest">
<span class="py-prompt">&gt;&gt;&gt; </span>trim((x**2+x)/x)
<span class="py-output">1 + x</span></pre>
<p>Recursively simplify expressions:</p>
<pre class="py-doctest">
<span class="py-prompt">&gt;&gt;&gt; </span>trim(sin((f(x)**2+f(x))/f(x)))
<span class="py-output">sin(1 + f(x))</span></pre>
</div></div>
            </div>
            <div class="function">
            <div class="functionHeader">def <a name="sympy.simplify.rewrite.apart">apart(f, z, **flags):</a></div>
            <div class="functionBody"><pre>Compute partial fraction decomposition of a rational function.

Given an rational function, performing only gcd operations over
the algebraic closue of its field of definition, compute full
partial fraction decomposition with fractions having linear
denominators.

For all other kinds of expressions the input is returned in an
unchanged form. Note however, that 'apart' function can thread
over sums and relational operators.

Note that no factorization of the initial denominator is needed,
howevert at some point root finding algorithms are executed but
for polynomials of much lower degree than the denominator.

If given an additional flag 'formal', then even root finding
algorithms are avoided and the result is formed as a combination
of formal summations over implicit roots of some polynomials.

>>> from sympy import *
>>> x,y = symbols('xy')

>>> apart(1/(x+2)/(x+1), x)
1/(1 + x) - 1/(2 + x)

>>> apart(Eq((x+1)/(x-1), E/x), x)
1 - 2/(1 - x) == E/x

For more information on the implemented algorithm refer to:

[1] M. Bronstein, B. Salvy, Full partial fraction decomposition
    of rational functions, in: M. Bronstein, ed., Proceedings
    ISSAC '93, ACM Press, Kiev, Ukraine, 1993, pp. 157-160.</pre></div>
            </div></body>
        